package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JEDCDemo9 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();) {
            connection.setAutoCommit(false);
            String sql = "UPDATE user\n" +
                    "SET password=?,nickname=?,``.user.age=?\n" +
                    "WHERE id=?;";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1, "789789");
            ps.setString(2, "大琪琪");
            ps.setInt(3, 40);
            ps.setInt(4, 2);
            int num = ps.executeUpdate();
            System.out.println(num > 0 ? "修改成功" : "修改失败");


            connection.commit();
            System.out.println("事务提交成功,修改算数了");
            // connection.rollback();
            // System.out.println("事务回滚了,修改不算数!");

        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}

